package com.baboba.rummy.card.validator;

import java.util.List;

import com.baboba.rummy.card.Card;
import com.baboba.rummy.card.Color;

public class HorizontalValidator<T extends Card> implements IValidator<T>{

	@Override
	public boolean validate(List<T> cards) {
		if (cards.size()<=2)
			return false;
		
		int max = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;
		Color lastColor = null;
		for (int i=0;i<cards.size();i++){
			if (cards.get(i).getNumber() == 0)
				continue;
			
			if (lastColor!=null && lastColor!=cards.get(i).getColor())
				return false;
			
			lastColor = cards.get(i).getColor();
			
			if (cards.get(i).getNumber()<min)
				min = cards.get(i).getNumber();
			else if (cards.get(i).getNumber()>max)
				max = cards.get(i).getNumber();
		}
		
		if ( max - min + 1 > cards.size())
			return false;
		
		return true;
	}

}
